/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package pl3.gui;

import java.util.HashMap;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Luis Alberto Pérez García <luixal@gmail.com>
 */
public class SetTableModel extends AbstractTableModel {

    private String[] rowNames;
    private HashMap<String, String> set;
    
    public SetTableModel(HashMap<String, String> set) {
        this.set = new HashMap<String, String>(set);
        // setting rowNames:
        this.rowNames = new String[set.keySet().size()];
        Integer counter = 0;
        for (String s:set.keySet()) {
            this.rowNames[counter] = s;
            counter++;
        }
    }
    
    public int getRowCount() {
        return this.rowNames.length;
    }

    public int getColumnCount() {
        return 2;
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0: return "Non Terminal";
            case 1: return "Set";
        }
        return null;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        if (columnIndex == 0) {
            return this.rowNames[rowIndex];
        } else {
            return this.set.get(this.rowNames[rowIndex]);
        }
    }

}
